package com.itheima.day06.extra2;

import com.itheima.day06.extra.ATMstatus;

import java.util.Scanner;

public class Login extends State<Activity> {
    Activity activity;

    public Login(Activity activity) {
        this.activity = activity;
    }

    @Override
    public void longin() {
        Scanner scanner = new Scanner(System.in);
        try {
            System.out.println("username:");
            activity.username = scanner.nextLine();
            System.out.println("password:");
            activity.password = scanner.nextLine();
            if ("root".equals(activity.username) && "root".equals(activity.password)) {
                activity.state = activity.usedState;
                activity.state.init();
            } else {
                activity.passwordErrorTimes++;
                if (activity.passwordErrorTimes >= 3) {
                    activity.state = activity.lockedState;
                    activity.state.init();
                } else {
                    System.out.println("错误次数" + activity.passwordErrorTimes);
                    activity.state.init();
                }
            }
        } catch (Exception e) {
            System.out.println("系统错误退出！");
        }
    }

    @Override
    public void saveMoney() {
        System.out.println("请先登录！");
    }

    @Override
    public void loadMoney() {
        System.out.println("请先登录！");
    }

    @Override
    public void init() {
        System.out.println("欢迎来到银行");
        longin();
    }
}
